<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable
          v-model="queryParams.date"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="股票ID" prop="stockId">
        <el-input
          v-model="queryParams.stockId"
          placeholder="请输入股票ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="股票代码" prop="stockCode">
        <el-input
          v-model="queryParams.stockCode"
          placeholder="请输入股票代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开盘价" prop="open">
        <el-input
          v-model="queryParams.open"
          placeholder="请输入开盘价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最高价" prop="high">
        <el-input
          v-model="queryParams.high"
          placeholder="请输入最高价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最低价" prop="low">
        <el-input
          v-model="queryParams.low"
          placeholder="请输入最低价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收盘价" prop="close">
        <el-input
          v-model="queryParams.close"
          placeholder="请输入收盘价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="前收盘价" prop="preClose">
        <el-input
          v-model="queryParams.preClose"
          placeholder="请输入前收盘价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成交量" prop="volume">
        <el-input
          v-model="queryParams.volume"
          placeholder="请输入成交量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成交金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入成交金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="5日移动平均线" prop="ma5">
        <el-input
          v-model="queryParams.ma5"
          placeholder="请输入5日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="10日移动平均线" prop="ma10">
        <el-input
          v-model="queryParams.ma10"
          placeholder="请输入10日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="20日移动平均线" prop="ma20">
        <el-input
          v-model="queryParams.ma20"
          placeholder="请输入20日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="30日移动平均线" prop="ma30">
        <el-input
          v-model="queryParams.ma30"
          placeholder="请输入30日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="60日移动平均线" prop="ma60">
        <el-input
          v-model="queryParams.ma60"
          placeholder="请输入60日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="120日移动平均线" prop="ma120">
        <el-input
          v-model="queryParams.ma120"
          placeholder="请输入120日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="200日移动平均线" prop="ma200">
        <el-input
          v-model="queryParams.ma200"
          placeholder="请输入200日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="250日移动平均线" prop="ma250">
        <el-input
          v-model="queryParams.ma250"
          placeholder="请输入250日移动平均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="120日成交量均线" prop="volume120">
        <el-input
          v-model="queryParams.volume120"
          placeholder="请输入120日成交量均线"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="k指标" prop="k">
        <el-input
          v-model="queryParams.k"
          placeholder="请输入k指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="d指标" prop="d">
        <el-input
          v-model="queryParams.d"
          placeholder="请输入d指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="j指标" prop="j">
        <el-input
          v-model="queryParams.j"
          placeholder="请输入j指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="dif指标" prop="dif">
        <el-input
          v-model="queryParams.dif"
          placeholder="请输入dif指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="dea指标" prop="dea">
        <el-input
          v-model="queryParams.dea"
          placeholder="请输入dea指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="macd指标" prop="macd">
        <el-input
          v-model="queryParams.macd"
          placeholder="请输入macd指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="rsi6指标" prop="rsi6">
        <el-input
          v-model="queryParams.rsi6"
          placeholder="请输入rsi6指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="rsi12指标" prop="rsi12">
        <el-input
          v-model="queryParams.rsi12"
          placeholder="请输入rsi12指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="rsi24指标" prop="rsi24">
        <el-input
          v-model="queryParams.rsi24"
          placeholder="请输入rsi24指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="wr6指标" prop="wr6">
        <el-input
          v-model="queryParams.wr6"
          placeholder="请输入wr6指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="wr10指标" prop="wr10">
        <el-input
          v-model="queryParams.wr10"
          placeholder="请输入wr10指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="cci指标" prop="cci">
        <el-input
          v-model="queryParams.cci"
          placeholder="请输入cci指标"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['stock:stockdayinfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['stock:stockdayinfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['stock:stockdayinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['stock:stockdayinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stockdayinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="记录ID" align="center" prop="dayInfoId" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="股票ID" align="center" prop="stockId" />
      <el-table-column label="股票代码" align="center" prop="stockCode" />
      <el-table-column label="开盘价" align="center" prop="open" />
      <el-table-column label="最高价" align="center" prop="high" />
      <el-table-column label="最低价" align="center" prop="low" />
      <el-table-column label="收盘价" align="center" prop="close" />
      <el-table-column label="前收盘价" align="center" prop="preClose" />
      <el-table-column label="成交量" align="center" prop="volume" />
      <el-table-column label="成交金额" align="center" prop="amount" />
      <el-table-column label="5日移动平均线" align="center" prop="ma5" />
      <el-table-column label="10日移动平均线" align="center" prop="ma10" />
      <el-table-column label="20日移动平均线" align="center" prop="ma20" />
      <el-table-column label="30日移动平均线" align="center" prop="ma30" />
      <el-table-column label="60日移动平均线" align="center" prop="ma60" />
      <el-table-column label="120日移动平均线" align="center" prop="ma120" />
      <el-table-column label="200日移动平均线" align="center" prop="ma200" />
      <el-table-column label="250日移动平均线" align="center" prop="ma250" />
      <el-table-column label="120日成交量均线" align="center" prop="volume120" />
      <el-table-column label="k指标" align="center" prop="k" />
      <el-table-column label="d指标" align="center" prop="d" />
      <el-table-column label="j指标" align="center" prop="j" />
      <el-table-column label="dif指标" align="center" prop="dif" />
      <el-table-column label="dea指标" align="center" prop="dea" />
      <el-table-column label="macd指标" align="center" prop="macd" />
      <el-table-column label="rsi6指标" align="center" prop="rsi6" />
      <el-table-column label="rsi12指标" align="center" prop="rsi12" />
      <el-table-column label="rsi24指标" align="center" prop="rsi24" />
      <el-table-column label="wr6指标" align="center" prop="wr6" />
      <el-table-column label="wr10指标" align="center" prop="wr10" />
      <el-table-column label="cci指标" align="center" prop="cci" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['stock:stockdayinfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['stock:stockdayinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改每日股票信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="股票ID" prop="stockId">
          <el-input v-model="form.stockId" placeholder="请输入股票ID" />
        </el-form-item>
        <el-form-item label="股票代码" prop="stockCode">
          <el-input v-model="form.stockCode" placeholder="请输入股票代码" />
        </el-form-item>
        <el-form-item label="开盘价" prop="open">
          <el-input v-model="form.open" placeholder="请输入开盘价" />
        </el-form-item>
        <el-form-item label="最高价" prop="high">
          <el-input v-model="form.high" placeholder="请输入最高价" />
        </el-form-item>
        <el-form-item label="最低价" prop="low">
          <el-input v-model="form.low" placeholder="请输入最低价" />
        </el-form-item>
        <el-form-item label="收盘价" prop="close">
          <el-input v-model="form.close" placeholder="请输入收盘价" />
        </el-form-item>
        <el-form-item label="前收盘价" prop="preClose">
          <el-input v-model="form.preClose" placeholder="请输入前收盘价" />
        </el-form-item>
        <el-form-item label="成交量" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入成交量" />
        </el-form-item>
        <el-form-item label="成交金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入成交金额" />
        </el-form-item>
        <el-form-item label="5日移动平均线" prop="ma5">
          <el-input v-model="form.ma5" placeholder="请输入5日移动平均线" />
        </el-form-item>
        <el-form-item label="10日移动平均线" prop="ma10">
          <el-input v-model="form.ma10" placeholder="请输入10日移动平均线" />
        </el-form-item>
        <el-form-item label="20日移动平均线" prop="ma20">
          <el-input v-model="form.ma20" placeholder="请输入20日移动平均线" />
        </el-form-item>
        <el-form-item label="30日移动平均线" prop="ma30">
          <el-input v-model="form.ma30" placeholder="请输入30日移动平均线" />
        </el-form-item>
        <el-form-item label="60日移动平均线" prop="ma60">
          <el-input v-model="form.ma60" placeholder="请输入60日移动平均线" />
        </el-form-item>
        <el-form-item label="120日移动平均线" prop="ma120">
          <el-input v-model="form.ma120" placeholder="请输入120日移动平均线" />
        </el-form-item>
        <el-form-item label="200日移动平均线" prop="ma200">
          <el-input v-model="form.ma200" placeholder="请输入200日移动平均线" />
        </el-form-item>
        <el-form-item label="250日移动平均线" prop="ma250">
          <el-input v-model="form.ma250" placeholder="请输入250日移动平均线" />
        </el-form-item>
        <el-form-item label="120日成交量均线" prop="volume120">
          <el-input v-model="form.volume120" placeholder="请输入120日成交量均线" />
        </el-form-item>
        <el-form-item label="k指标" prop="k">
          <el-input v-model="form.k" placeholder="请输入k指标" />
        </el-form-item>
        <el-form-item label="d指标" prop="d">
          <el-input v-model="form.d" placeholder="请输入d指标" />
        </el-form-item>
        <el-form-item label="j指标" prop="j">
          <el-input v-model="form.j" placeholder="请输入j指标" />
        </el-form-item>
        <el-form-item label="dif指标" prop="dif">
          <el-input v-model="form.dif" placeholder="请输入dif指标" />
        </el-form-item>
        <el-form-item label="dea指标" prop="dea">
          <el-input v-model="form.dea" placeholder="请输入dea指标" />
        </el-form-item>
        <el-form-item label="macd指标" prop="macd">
          <el-input v-model="form.macd" placeholder="请输入macd指标" />
        </el-form-item>
        <el-form-item label="rsi6指标" prop="rsi6">
          <el-input v-model="form.rsi6" placeholder="请输入rsi6指标" />
        </el-form-item>
        <el-form-item label="rsi12指标" prop="rsi12">
          <el-input v-model="form.rsi12" placeholder="请输入rsi12指标" />
        </el-form-item>
        <el-form-item label="rsi24指标" prop="rsi24">
          <el-input v-model="form.rsi24" placeholder="请输入rsi24指标" />
        </el-form-item>
        <el-form-item label="wr6指标" prop="wr6">
          <el-input v-model="form.wr6" placeholder="请输入wr6指标" />
        </el-form-item>
        <el-form-item label="wr10指标" prop="wr10">
          <el-input v-model="form.wr10" placeholder="请输入wr10指标" />
        </el-form-item>
        <el-form-item label="cci指标" prop="cci">
          <el-input v-model="form.cci" placeholder="请输入cci指标" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStockdayinfo, getStockdayinfo, delStockdayinfo, addStockdayinfo, updateStockdayinfo } from "@/api/stock/stockdayinfo";

export default {
  name: "Stockdayinfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 每日股票信息表格数据
      stockdayinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: null,
        stockId: null,
        stockCode: null,
        open: null,
        high: null,
        low: null,
        close: null,
        preClose: null,
        volume: null,
        amount: null,
        ma5: null,
        ma10: null,
        ma20: null,
        ma30: null,
        ma60: null,
        ma120: null,
        ma200: null,
        ma250: null,
        volume120: null,
        k: null,
        d: null,
        j: null,
        dif: null,
        dea: null,
        macd: null,
        rsi6: null,
        rsi12: null,
        rsi24: null,
        wr6: null,
        wr10: null,
        cci: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询每日股票信息列表 */
    getList() {
      this.loading = true;
      listStockdayinfo(this.queryParams).then(response => {
        this.stockdayinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        dayInfoId: null,
        date: null,
        stockId: null,
        stockCode: null,
        open: null,
        high: null,
        low: null,
        close: null,
        preClose: null,
        volume: null,
        amount: null,
        ma5: null,
        ma10: null,
        ma20: null,
        ma30: null,
        ma60: null,
        ma120: null,
        ma200: null,
        ma250: null,
        volume120: null,
        k: null,
        d: null,
        j: null,
        dif: null,
        dea: null,
        macd: null,
        rsi6: null,
        rsi12: null,
        rsi24: null,
        wr6: null,
        wr10: null,
        cci: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.dayInfoId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加每日股票信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dayInfoId = row.dayInfoId || this.ids
      getStockdayinfo(dayInfoId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改每日股票信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.dayInfoId != null) {
            updateStockdayinfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStockdayinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dayInfoIds = row.dayInfoId || this.ids;
      this.$modal.confirm('是否确认删除每日股票信息编号为"' + dayInfoIds + '"的数据项？').then(function() {
        return delStockdayinfo(dayInfoIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('stock/stockdayinfo/export', {
        ...this.queryParams
      }, `stockdayinfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
